//
//  GoogleAPICaller.m
//  iWeather
//
//  Created by Quan Lam on 11/15/13.
//  Copyright (c) 2013 Vo Thi My Hanh (FSU1.BU19). All rights reserved.
//

#import "GoogleAPICaller.h"
#import "APIService.h"
#import "WeatherDefines.h"
#import "JSON.h"
#import "AppDelegate.h"

#import <ifaddrs.h>
#import <arpa/inet.h>


@implementation GoogleAPICaller
-(void)directionsAPICallfrom:(NSString *)fromPOI to:(NSString *)toPOI

{
    NSString* url =  [NSString stringWithFormat:@"http://maps.googleapis.com/maps/api/directions/json?origin=%@&destination=%@&sensor=true",fromPOI,toPOI ];
    
    SEL finishSelector = @selector(directionsAPIRequestFinished:);
    _asiHttpRequest=[ASIHTTPRequest requestWithURL:[NSURL URLWithString:url]];
    [_asiHttpRequest setRequestMethod:@"GET"];
    [_asiHttpRequest setDelegate:self];
    [_asiHttpRequest setDidFinishSelector:finishSelector];
    [_asiHttpRequest setTimeOutSeconds:120];
    [_asiHttpRequest startAsynchronous];
}

- (void) directionsAPIRequestFinished:(ASIHTTPRequest *)request
{
    SBJsonParser * parser =[[SBJsonParser alloc]init];
    // parse json
    NSDictionary* data =(NSDictionary*)[parser objectWithString:request.responseString];
    [self.callerDelegate directionsAPIRequestFinished:data];
    [parser release];
    
}

-(void)serviceRequestTimeOut {
    NSLog(@"Damn you two");
}

@end
